package com.atguigu.gmall.list.controller;

import com.atguigu.gmall.common.result.Result;
import com.atguigu.gmall.list.service.ListService;
import com.atguigu.gmall.model.list.SearchParam;
import com.atguigu.gmall.model.list.SearchResponseAttrVo;
import com.atguigu.gmall.model.list.SearchResponseVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 *1.使用swagger 创建索引库
 *2.使用swagger mappings映射
 * 3.使用swagger 上架商品
 * 4.使用swagger 删除商品
 */
@RestController
@RequestMapping("/api/list")
public class ListApiController {
    @Autowired
    private ListService listService;


    //创建索引库 并 映射 mappings
    @GetMapping("/createIndex")
    public Result createIndex(){
        listService.createIndex();
        return Result.ok();
    }
    //上架 添加商品数据到索引库
    @GetMapping("onSale/{skuId}")
    public Result onSale(@PathVariable Long skuId){
        listService.onSale(skuId);
        return Result.ok();
    }

    //下架 删除商品数据
    @GetMapping("cancelSale/{skuId}")
    public Result cancelSale(@PathVariable Long skuId){
        listService.cancelSale(skuId);
        return Result.ok();
    }
    //商品热度评分 更新操作 GET请求基本上是简单的类型
    @GetMapping("/hotScore/{skuId}/{score}")
    public Result hotScore(@PathVariable Long skuId,@PathVariable Integer score){
        listService.hotScore(skuId,score);
        return Result.ok();
    }

    //开始搜索
    @PostMapping("/search")//Post请求基本是@RequestBody
    public SearchResponseVo search(@RequestBody SearchParam searchParam){
        //从请求体中接收到JSON串 @RequestBody 转成SearchParam searchParam
        return listService.search(searchParam);
    }


}
